package m202401.d02;

import java.util.HashMap;
import java.util.Map;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/2 08:44
 */
//383. 赎金信
public class Q383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        int[] map = new int['z' - 'a' + 1];
//        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < magazine.length(); i++) {
            char c = magazine.charAt(i);
            map[c - 'a'] += 1;
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            char c = ransomNote.charAt(i);
            if (map[c - 'a'] <= 0) {
                return false;
            }
            map[c - 'a'] -= 1;
        }
        return true;
    }
}
